﻿using DBServer.Selenium.Extenium.Exception;
using DBServer.Selenium.Extenium.Path;
using Selenium;

namespace DBServer.Selenium.Extenium.Fixtures
{
    public class TextAreaFixture : ExtComponentFixture
    {
        private readonly IPath _path;

        public TextAreaFixture(ISelenium driver, IPath path)
            : base(driver, path)
        {
            _path = path;
        }


        public TextAreaFixture SetText(string text)
        {
            SafeExec(_path.Eval() + ".setValue('" + text + "');");
            return this;
        }

        public TextAreaFixture RequireText(string text)
        {
            var value = SafeExec(_path.Eval() + ".getValue();");

            if (value != text)
            {
                throw new ExteniumException("Text not found: " + text);
            }
            return this;
        }

        public TextAreaFixture RequireValid()
        {
            var isValid = bool.Parse(SafeExec(_path.Eval() + ".isValid();"));

            if (isValid)
            {
                throw new ExteniumException("TextArea is not valid");
            }
            return this;
        }

        public TextAreaFixture RequireInvalid()
        {
            var isValid = bool.Parse(SafeExec(_path.Eval() + ".isValid();"));

            if (!isValid)
            {
                throw new ExteniumException("TextArea is valid");
            }
            return this;
        }

        
    }
}